ca8ba1
@@ -594,9 +594,11 @@
void subqueryRestrictionsCheck(RowResolver parentQueryRR,
 
     // figure out if there is group by
     boolean noImplicityGby = true;
-    if ( insertClause.getChildCount() > 3 &&
-            insertClause.getChild(3).getType() == HiveParser.TOK_GROUPBY ) {
+    for(int i=0; i<insertClause.getChildCount(); i++) {
+      if(insertClause.getChild(i).getType() == HiveParser.TOK_GROUPBY) {
         noImplicityGby = false;
+        break;
+      }
     }
 
     /*
